package mts.strategies;

import mts.groupdispatcher.ElevatorControllerConnection;
import mts.groupdispatcher.FloorRequest;
import mts.messages.StatusMessage;

public class SimpleStrategy extends MediaStrategy {
	
	@Override
	public byte addFloorRequest(FloorRequest floorRequest) {
		byte bestCarNum = -1;
		int nextCarSize = Integer.MAX_VALUE;
		for (ElevatorControllerConnection elevatorControllerConnection: groupDispatcher.getElevatorControllers()) {
			StatusMessage ecStatusMessage = elevatorControllerConnection.getCurrentStatus();
			int size = ecStatusMessage.getCurrentHallCalls().size() + elevatorControllerConnection.getPendingNewHallCalls().size();
			if (size < nextCarSize) {				
				bestCarNum = ecStatusMessage.getCar();
				nextCarSize = size;
			}
		}
		
		groupDispatcher.assignNewHallCallToElevatorController(bestCarNum, floorRequest);
		return bestCarNum;
	}
}
